package spotor.client.util;

import java.io.InputStream;
import java.util.regex.Pattern;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

import android.text.format.Time;

public class ParserUtils {
	
	private static final Pattern sSanitizePattern = Pattern.compile("");
	
	private static Time sTime = new Time();
	private static XmlPullParserFactory sFactory;
	
	/***
	 * 
	 */
	public static String sanitizeId(String input){
		return sanitizeId(input, false);
	}
	
	/**
	 * 将传入的字符串构造成安全的Uri ContentProvider Paths
	 */
	public static String sanitizeId(String input,boolean stripParen){
		if(input == null) return null;
		if(stripParen){
			input = sSanitizePattern.matcher(input.toLowerCase()).replaceAll("");
		}
		return sSanitizePattern.matcher(input.toLowerCase()).replaceAll("");		
	}
	
    /**
     * Build and return a new {@link XmlPullParser} with the given
     * {@link InputStream} assigned to it.
     */
    public static XmlPullParser newPullParser(InputStream input) throws XmlPullParserException {
        if (sFactory == null) {
            sFactory = XmlPullParserFactory.newInstance();
        }
        final XmlPullParser parser = sFactory.newPullParser();
        parser.setInput(input, null);
        return parser;
    }
    
    /***
     *	解析时间
     */
    public static long parseTime(String time){
    	sTime.parse3339(time);
    	return sTime.toMillis(false);
    }
    
    
    /*****/
    public interface Tags{
    	
    }
    

}
